use "$project_path/data/4_regdata/dynamics/regdata_dynamics", clear

** Appendix Figure E.1(a)

rdrobust diff_m1_general_chix runvar if relative_year==0
local rdd_tau : di %8.3f e(tau_cl)
local rdd_lb : di %8.3f e(ci_l_rb)
local rdd_lb = subinstr("`rdd_lb'", " ", "", .)
local rdd_ub : di %8.3f e(ci_r_rb)
local rdd_ub = subinstr("`rdd_ub'", " ", "", .)
local rdd_pval : di %8.3f e(pv_rb)
if e(pv_rb)<0.001 local rdd_pval = "<0.001"
local N = e(N)
local rd_est = "RD est.: `rdd_tau' [`rdd_lb', `rdd_ub']. p-value: `rdd_pval'. N = `N'"

rdplot diff_m1_general_chix runvar if relative_year==0 & inrange(runvar, -20, 20), p(1) nbins(10 10) graph_options(xtitle("Margin of victory of the challenger", size(large)) ylabel(-0.5(0.25)0.5, angle(0) labsize(large)) graphregion(color(white)) note("`rd_est'", tstyle(size(medlarge))) xlabel(-20(5)20, labsize(large)) ytitle("Standard deviations", size(large)) legend(off) title("Year 0", size(large)))
graph export "$project_path/output/appendix_figures/Appendix_Figure_E1a.pdf", as(pdf) name("Graph") replace

** Appendix Figure E.1(b)

rdrobust diff_m1_general_chix runvar if relative_year==1
local rdd_tau : di %8.3f e(tau_cl)
local rdd_lb : di %8.3f e(ci_l_rb)
local rdd_lb = subinstr("`rdd_lb'", " ", "", .)
local rdd_ub : di %8.3f e(ci_r_rb)
local rdd_ub = subinstr("`rdd_ub'", " ", "", .)
local rdd_pval : di %8.3f e(pv_rb)
if e(pv_rb)<0.001 local rdd_pval = "<0.001"
local N = e(N)
local rd_est = "RD est.: `rdd_tau' [`rdd_lb', `rdd_ub']. p-value: `rdd_pval'. N = `N'"

rdplot diff_m1_general_chix runvar if relative_year==1 & inrange(runvar, -20, 20), p(1) nbins(10 10) graph_options(xtitle("Margin of victory of the challenger", size(large)) ylabel(-0.5(0.25)0.5, angle(0) labsize(large)) graphregion(color(white)) note("`rd_est'", tstyle(size(medlarge))) xlabel(-20(5)20, labsize(large)) ytitle("Standard deviations", size(large)) legend(off) title("Year 1", size(large)))
graph export "$project_path/output/appendix_figures/Appendix_Figure_E1b.pdf", as(pdf) name("Graph") replace

** Appendix Figure E.1(c)

rdrobust diff_m1_general_chix runvar if relative_year==2
local rdd_tau : di %8.3f e(tau_cl)
local rdd_lb : di %8.3f e(ci_l_rb)
local rdd_lb = subinstr("`rdd_lb'", " ", "", .)
local rdd_ub : di %8.3f e(ci_r_rb)
local rdd_ub = subinstr("`rdd_ub'", " ", "", .)
local rdd_pval : di %8.3f e(pv_rb)
if e(pv_rb)<0.001 local rdd_pval = "<0.001"
local N = e(N)
local rd_est = "RD est.: `rdd_tau' [`rdd_lb', `rdd_ub']. p-value: `rdd_pval'. N = `N'"

rdplot diff_m1_general_chix runvar if relative_year==2 & inrange(runvar, -20, 20), p(1) nbins(10 10) graph_options(xtitle("Margin of victory of the challenger", size(large)) ylabel(-0.5(0.25)0.5, angle(0) labsize(large)) graphregion(color(white)) note("`rd_est'", tstyle(size(medlarge))) xlabel(-20(5)20, labsize(large)) ytitle("Standard deviations", size(large)) legend(off) title("Year 2", size(large)))
graph export "$project_path/output/appendix_figures/Appendix_Figure_E1c.pdf", as(pdf) name("Graph") replace

** Appendix Figure E.1(d)

rdrobust diff_m1_general_chix runvar if relative_year==3
local rdd_tau : di %8.3f e(tau_cl)
local rdd_lb : di %8.3f e(ci_l_rb)
local rdd_lb = subinstr("`rdd_lb'", " ", "", .)
local rdd_ub : di %8.3f e(ci_r_rb)
local rdd_ub = subinstr("`rdd_ub'", " ", "", .)
local rdd_pval : di %8.3f e(pv_rb)
if e(pv_rb)<0.001 local rdd_pval = "<0.001"
local N = e(N)
local rd_est = "RD est.: `rdd_tau' [`rdd_lb', `rdd_ub']. p-value: `rdd_pval'. N = `N'"

rdplot diff_m1_general_chix runvar if relative_year==3 & inrange(runvar, -20, 20), p(1) nbins(10 10) graph_options(xtitle("Margin of victory of the challenger", size(large)) ylabel(-0.5(0.25)0.5, angle(0) labsize(large)) graphregion(color(white)) note("`rd_est'", tstyle(size(medlarge))) xlabel(-20(5)20, labsize(large)) ytitle("Standard deviations", size(large)) legend(off) title("Year 3", size(large)))
graph export "$project_path/output/appendix_figures/Appendix_Figure_E1d.pdf", as(pdf) name("Graph") replace

** Appendix Figure E.1(e)

rdrobust diff_m1_general_chix runvar if relative_year==4
local rdd_tau : di %8.3f e(tau_cl)
local rdd_lb : di %8.3f e(ci_l_rb)
local rdd_lb = subinstr("`rdd_lb'", " ", "", .)
local rdd_ub : di %8.3f e(ci_r_rb)
local rdd_ub = subinstr("`rdd_ub'", " ", "", .)
local rdd_pval : di %8.3f e(pv_rb)
if e(pv_rb)<0.001 local rdd_pval = "<0.001"
local N = e(N)
local rd_est = "RD est.: `rdd_tau' [`rdd_lb', `rdd_ub']. p-value: `rdd_pval'. N = `N'"

rdplot diff_m1_general_chix runvar if relative_year==4 & inrange(runvar, -20, 20), p(1) nbins(10 10) graph_options(xtitle("Margin of victory of the challenger", size(large)) ylabel(-0.5(0.25)0.5, angle(0) labsize(large)) graphregion(color(white)) note("`rd_est'", tstyle(size(medlarge))) xlabel(-20(5)20, labsize(large)) ytitle("Standard deviations", size(large)) legend(off) title("Year 4", size(large)))
graph export "$project_path/output/appendix_figures/Appendix_Figure_E1e.pdf", as(pdf) name("Graph") replace

** Appendix Figure E.1(f)

rdrobust diff_m1_general_chix runvar if relative_year==5
local rdd_tau : di %8.3f e(tau_cl)
local rdd_lb : di %8.3f e(ci_l_rb)
local rdd_lb = subinstr("`rdd_lb'", " ", "", .)
local rdd_ub : di %8.3f e(ci_r_rb)
local rdd_ub = subinstr("`rdd_ub'", " ", "", .)
local rdd_pval : di %8.3f e(pv_rb)
if e(pv_rb)<0.001 local rdd_pval = "<0.001"
local N = e(N)
local rd_est = "RD est.: `rdd_tau' [`rdd_lb', `rdd_ub']. p-value: `rdd_pval'. N = `N'"

rdplot diff_m1_general_chix runvar if relative_year==5 & inrange(runvar, -20, 20), p(1) nbins(10 10) graph_options(xtitle("Margin of victory of the challenger", size(large)) ylabel(-0.5(0.25)0.5, angle(0) labsize(large)) graphregion(color(white)) note("`rd_est'", tstyle(size(medlarge))) xlabel(-20(5)20, labsize(large)) ytitle("Standard deviations", size(large)) legend(off) title("Year 5", size(large)))
graph export "$project_path/output/appendix_figures/Appendix_Figure_E1f.pdf", as(pdf) name("Graph") replace

